﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using Common;
using Basic.Business;
using Basic.Model.Entity;

public partial class Basic_Background_MenuNodeManage : System.Web.UI.Page
{
    protected string treeListStr = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Tools.IsAdminSessionValid())
            Tools.ShowInfo(StringTable.ErrorSessionTimeOut, "../Background/AdminLogin.aspx", "_self");
        StringBuilder _treeListStr = new StringBuilder();
        IList<MenuNode> list = MenuNodeAdmin.GetAllByTree();
        _treeListStr.Append("<li class=\"folder f-open first\"><span>所有菜单</span><a class=\"operationLink\" href=\"#\" onclick=\"window.addMenuNode('0');\">新增</a><ul>");
        buildTreeList(_treeListStr, list, 0);
        _treeListStr.Append("</ul></li>");
        treeListStr = _treeListStr.ToString();
    }
    protected void buildTreeList(StringBuilder _treeListStr, IList<MenuNode> list, int menuParentId)
    {
        foreach (MenuNode menuNode in list)
        {
            if (menuNode.menuParentId == menuParentId)
            {
                if (menuNode.menuUrl.Equals(""))
                {
                    _treeListStr.AppendFormat("<li class=\"folder f-open\"><span>{0}</span><ul>", menuNode.menuName);
                }
                else
                {
                    _treeListStr.AppendFormat("<li class=\"doc\"><span><a>{0}</a></span></li>", menuNode.menuName);
                }
                buildTreeList(_treeListStr, list, menuNode.menuId);
                if (menuNode.menuUrl.Equals(""))
                {
                    _treeListStr.Append("</ul></li>");
                }
            }
        }
    }
}
